<?php


abstract class BaseShippingPeer {

	
	const DATABASE_NAME = 'propel';

	
	const TABLE_NAME = 'shipping';

	
	const CLASS_DEFAULT = 'lib.model.Shipping';

	
	const NUM_COLUMNS = 25;

	
	const NUM_LAZY_LOAD_COLUMNS = 0;


	
	const ID = 'shipping.ID';

	
	const STATUS_ID = 'shipping.STATUS_ID';

	
	const COMPANY_ID = 'shipping.COMPANY_ID';

	
	const WEIGHT_G_FROM = 'shipping.WEIGHT_G_FROM';

	
	const WEIGHT_G_TO = 'shipping.WEIGHT_G_TO';

	
	const VOLUME_FROM = 'shipping.VOLUME_FROM';

	
	const VOLUME_TO = 'shipping.VOLUME_TO';

	
	const HEIGHT_FROM = 'shipping.HEIGHT_FROM';

	
	const HEIGHT_TO = 'shipping.HEIGHT_TO';

	
	const WIDTH_FROM = 'shipping.WIDTH_FROM';

	
	const WIDTH_TO = 'shipping.WIDTH_TO';

	
	const LENGTH_FROM = 'shipping.LENGTH_FROM';

	
	const LENGTH_TO = 'shipping.LENGTH_TO';

	
	const DISTANCE = 'shipping.DISTANCE';

	
	const EUROPEAN_UNION = 'shipping.EUROPEAN_UNION';

	
	const COUNTRY_FROM = 'shipping.COUNTRY_FROM';

	
	const CITY_FROM = 'shipping.CITY_FROM';

	
	const COUNTRY_TO = 'shipping.COUNTRY_TO';

	
	const CITY_TO = 'shipping.CITY_TO';

	
	const IN_SAME_CIUNTRY = 'shipping.IN_SAME_CIUNTRY';

	
	const TIME_HOURS = 'shipping.TIME_HOURS';

	
	const PRICE = 'shipping.PRICE';

	
	const CURRENCY = 'shipping.CURRENCY';

	
	const CREATED_AT = 'shipping.CREATED_AT';

	
	const VALID_TIL = 'shipping.VALID_TIL';

	
	private static $phpNameMap = null;


	
	private static $fieldNames = array (
		BasePeer::TYPE_PHPNAME => array ('Id', 'StatusId', 'CompanyId', 'WeightGFrom', 'WeightGTo', 'VolumeFrom', 'VolumeTo', 'HeightFrom', 'HeightTo', 'WidthFrom', 'WidthTo', 'LengthFrom', 'LengthTo', 'Distance', 'EuropeanUnion', 'CountryFrom', 'CityFrom', 'CountryTo', 'CityTo', 'InSameCiuntry', 'TimeHours', 'Price', 'Currency', 'CreatedAt', 'ValidTil', ),
		BasePeer::TYPE_COLNAME => array (ShippingPeer::ID, ShippingPeer::STATUS_ID, ShippingPeer::COMPANY_ID, ShippingPeer::WEIGHT_G_FROM, ShippingPeer::WEIGHT_G_TO, ShippingPeer::VOLUME_FROM, ShippingPeer::VOLUME_TO, ShippingPeer::HEIGHT_FROM, ShippingPeer::HEIGHT_TO, ShippingPeer::WIDTH_FROM, ShippingPeer::WIDTH_TO, ShippingPeer::LENGTH_FROM, ShippingPeer::LENGTH_TO, ShippingPeer::DISTANCE, ShippingPeer::EUROPEAN_UNION, ShippingPeer::COUNTRY_FROM, ShippingPeer::CITY_FROM, ShippingPeer::COUNTRY_TO, ShippingPeer::CITY_TO, ShippingPeer::IN_SAME_CIUNTRY, ShippingPeer::TIME_HOURS, ShippingPeer::PRICE, ShippingPeer::CURRENCY, ShippingPeer::CREATED_AT, ShippingPeer::VALID_TIL, ),
		BasePeer::TYPE_FIELDNAME => array ('id', 'status_id', 'company_id', 'weight_g_from', 'weight_g_to', 'volume_from', 'volume_to', 'height_from', 'height_to', 'width_from', 'width_to', 'length_from', 'length_to', 'distance', 'european_union', 'country_from', 'city_from', 'country_to', 'city_to', 'in_same_ciuntry', 'time_hours', 'price', 'currency', 'created_at', 'valid_til', ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, )
	);

	
	private static $fieldKeys = array (
		BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'StatusId' => 1, 'CompanyId' => 2, 'WeightGFrom' => 3, 'WeightGTo' => 4, 'VolumeFrom' => 5, 'VolumeTo' => 6, 'HeightFrom' => 7, 'HeightTo' => 8, 'WidthFrom' => 9, 'WidthTo' => 10, 'LengthFrom' => 11, 'LengthTo' => 12, 'Distance' => 13, 'EuropeanUnion' => 14, 'CountryFrom' => 15, 'CityFrom' => 16, 'CountryTo' => 17, 'CityTo' => 18, 'InSameCiuntry' => 19, 'TimeHours' => 20, 'Price' => 21, 'Currency' => 22, 'CreatedAt' => 23, 'ValidTil' => 24, ),
		BasePeer::TYPE_COLNAME => array (ShippingPeer::ID => 0, ShippingPeer::STATUS_ID => 1, ShippingPeer::COMPANY_ID => 2, ShippingPeer::WEIGHT_G_FROM => 3, ShippingPeer::WEIGHT_G_TO => 4, ShippingPeer::VOLUME_FROM => 5, ShippingPeer::VOLUME_TO => 6, ShippingPeer::HEIGHT_FROM => 7, ShippingPeer::HEIGHT_TO => 8, ShippingPeer::WIDTH_FROM => 9, ShippingPeer::WIDTH_TO => 10, ShippingPeer::LENGTH_FROM => 11, ShippingPeer::LENGTH_TO => 12, ShippingPeer::DISTANCE => 13, ShippingPeer::EUROPEAN_UNION => 14, ShippingPeer::COUNTRY_FROM => 15, ShippingPeer::CITY_FROM => 16, ShippingPeer::COUNTRY_TO => 17, ShippingPeer::CITY_TO => 18, ShippingPeer::IN_SAME_CIUNTRY => 19, ShippingPeer::TIME_HOURS => 20, ShippingPeer::PRICE => 21, ShippingPeer::CURRENCY => 22, ShippingPeer::CREATED_AT => 23, ShippingPeer::VALID_TIL => 24, ),
		BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'status_id' => 1, 'company_id' => 2, 'weight_g_from' => 3, 'weight_g_to' => 4, 'volume_from' => 5, 'volume_to' => 6, 'height_from' => 7, 'height_to' => 8, 'width_from' => 9, 'width_to' => 10, 'length_from' => 11, 'length_to' => 12, 'distance' => 13, 'european_union' => 14, 'country_from' => 15, 'city_from' => 16, 'country_to' => 17, 'city_to' => 18, 'in_same_ciuntry' => 19, 'time_hours' => 20, 'price' => 21, 'currency' => 22, 'created_at' => 23, 'valid_til' => 24, ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, )
	);

	
	public static function getMapBuilder()
	{
		include_once 'lib/model/map/ShippingMapBuilder.php';
		return BasePeer::getMapBuilder('lib.model.map.ShippingMapBuilder');
	}
	
	public static function getPhpNameMap()
	{
		if (self::$phpNameMap === null) {
			$map = ShippingPeer::getTableMap();
			$columns = $map->getColumns();
			$nameMap = array();
			foreach ($columns as $column) {
				$nameMap[$column->getPhpName()] = $column->getColumnName();
			}
			self::$phpNameMap = $nameMap;
		}
		return self::$phpNameMap;
	}
	
	static public function translateFieldName($name, $fromType, $toType)
	{
		$toNames = self::getFieldNames($toType);
		$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
		if ($key === null) {
			throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
		}
		return $toNames[$key];
	}

	

	static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
	{
		if (!array_key_exists($type, self::$fieldNames)) {
			throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
		}
		return self::$fieldNames[$type];
	}

	
	public static function alias($alias, $column)
	{
		return str_replace(ShippingPeer::TABLE_NAME.'.', $alias.'.', $column);
	}

	
	public static function addSelectColumns(Criteria $criteria)
	{

		$criteria->addSelectColumn(ShippingPeer::ID);

		$criteria->addSelectColumn(ShippingPeer::STATUS_ID);

		$criteria->addSelectColumn(ShippingPeer::COMPANY_ID);

		$criteria->addSelectColumn(ShippingPeer::WEIGHT_G_FROM);

		$criteria->addSelectColumn(ShippingPeer::WEIGHT_G_TO);

		$criteria->addSelectColumn(ShippingPeer::VOLUME_FROM);

		$criteria->addSelectColumn(ShippingPeer::VOLUME_TO);

		$criteria->addSelectColumn(ShippingPeer::HEIGHT_FROM);

		$criteria->addSelectColumn(ShippingPeer::HEIGHT_TO);

		$criteria->addSelectColumn(ShippingPeer::WIDTH_FROM);

		$criteria->addSelectColumn(ShippingPeer::WIDTH_TO);

		$criteria->addSelectColumn(ShippingPeer::LENGTH_FROM);

		$criteria->addSelectColumn(ShippingPeer::LENGTH_TO);

		$criteria->addSelectColumn(ShippingPeer::DISTANCE);

		$criteria->addSelectColumn(ShippingPeer::EUROPEAN_UNION);

		$criteria->addSelectColumn(ShippingPeer::COUNTRY_FROM);

		$criteria->addSelectColumn(ShippingPeer::CITY_FROM);

		$criteria->addSelectColumn(ShippingPeer::COUNTRY_TO);

		$criteria->addSelectColumn(ShippingPeer::CITY_TO);

		$criteria->addSelectColumn(ShippingPeer::IN_SAME_CIUNTRY);

		$criteria->addSelectColumn(ShippingPeer::TIME_HOURS);

		$criteria->addSelectColumn(ShippingPeer::PRICE);

		$criteria->addSelectColumn(ShippingPeer::CURRENCY);

		$criteria->addSelectColumn(ShippingPeer::CREATED_AT);

		$criteria->addSelectColumn(ShippingPeer::VALID_TIL);

	}

	const COUNT = 'COUNT(shipping.ID)';
	const COUNT_DISTINCT = 'COUNT(DISTINCT shipping.ID)';

	
	public static function doCount(Criteria $criteria, $distinct = false, $con = null)
	{
				$criteria = clone $criteria;

				$criteria->clearSelectColumns()->clearOrderByColumns();
		if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
			$criteria->addSelectColumn(ShippingPeer::COUNT_DISTINCT);
		} else {
			$criteria->addSelectColumn(ShippingPeer::COUNT);
		}

				foreach($criteria->getGroupByColumns() as $column)
		{
			$criteria->addSelectColumn($column);
		}

		$rs = ShippingPeer::doSelectRS($criteria, $con);
		if ($rs->next()) {
			return $rs->getInt(1);
		} else {
						return 0;
		}
	}
	
	public static function doSelectOne(Criteria $criteria, $con = null)
	{
		$critcopy = clone $criteria;
		$critcopy->setLimit(1);
		$objects = ShippingPeer::doSelect($critcopy, $con);
		if ($objects) {
			return $objects[0];
		}
		return null;
	}
	
	public static function doSelect(Criteria $criteria, $con = null)
	{
		return ShippingPeer::populateObjects(ShippingPeer::doSelectRS($criteria, $con));
	}
	
	public static function doSelectRS(Criteria $criteria, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		if (!$criteria->getSelectColumns()) {
			$criteria = clone $criteria;
			ShippingPeer::addSelectColumns($criteria);
		}

				$criteria->setDbName(self::DATABASE_NAME);

						return BasePeer::doSelect($criteria, $con);
	}
	
	public static function populateObjects(ResultSet $rs)
	{
		$results = array();
	
				$cls = ShippingPeer::getOMClass();
		$cls = Propel::import($cls);
				while($rs->next()) {
		
			$obj = new $cls();
			$obj->hydrate($rs);
			$results[] = $obj;
			
		}
		return $results;
	}

  
  public static function doSelectWithI18n(Criteria $c, $culture = null, $con = null)
  {
        $c = clone $c;
    if ($culture === null)
    {
      $culture = sfContext::getInstance()->getUser()->getCulture();
    }

        if ($c->getDbName() == Propel::getDefaultDB())
    {
      $c->setDbName(self::DATABASE_NAME);
    }

    ShippingPeer::addSelectColumns($c);
    $startcol = (ShippingPeer::NUM_COLUMNS - ShippingPeer::NUM_LAZY_LOAD_COLUMNS) + 1;

    ShippingI18nPeer::addSelectColumns($c);

    $c->addJoin(ShippingPeer::ID, ShippingI18nPeer::ID);
    $c->add(ShippingI18nPeer::CULTURE, $culture);

    $rs = BasePeer::doSelect($c, $con);
    $results = array();

    while($rs->next()) {

      $omClass = ShippingPeer::getOMClass();

      $cls = Propel::import($omClass);
      $obj1 = new $cls();
      $obj1->hydrate($rs);
      $obj1->setCulture($culture);

      $omClass = ShippingI18nPeer::getOMClass($rs, $startcol);

      $cls = Propel::import($omClass);
      $obj2 = new $cls();
      $obj2->hydrate($rs, $startcol);

      $obj1->setShippingI18nForCulture($obj2, $culture);
      $obj2->setShipping($obj1);

      $results[] = $obj1;
    }
    return $results;
  }

	
	public static function getTableMap()
	{
		return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
	}

	
	public static function getOMClass()
	{
		return ShippingPeer::CLASS_DEFAULT;
	}

	
	public static function doInsert($values, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		if ($values instanceof Criteria) {
			$criteria = clone $values; 		} else {
			$criteria = $values->buildCriteria(); 		}

		$criteria->remove(ShippingPeer::ID); 

				$criteria->setDbName(self::DATABASE_NAME);

		try {
									$con->begin();
			$pk = BasePeer::doInsert($criteria, $con);
			$con->commit();
		} catch(PropelException $e) {
			$con->rollback();
			throw $e;
		}

		return $pk;
	}

	
	public static function doUpdate($values, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$selectCriteria = new Criteria(self::DATABASE_NAME);

		if ($values instanceof Criteria) {
			$criteria = clone $values; 
			$comparison = $criteria->getComparison(ShippingPeer::ID);
			$selectCriteria->add(ShippingPeer::ID, $criteria->remove(ShippingPeer::ID), $comparison);

		} else { 			$criteria = $values->buildCriteria(); 			$selectCriteria = $values->buildPkeyCriteria(); 		}

				$criteria->setDbName(self::DATABASE_NAME);

		return BasePeer::doUpdate($selectCriteria, $criteria, $con);
	}

	
	public static function doDeleteAll($con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}
		$affectedRows = 0; 		try {
									$con->begin();
			$affectedRows += ShippingPeer::doOnDeleteCascade(new Criteria(), $con);
			$affectedRows += BasePeer::doDeleteAll(ShippingPeer::TABLE_NAME, $con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	 public static function doDelete($values, $con = null)
	 {
		if ($con === null) {
			$con = Propel::getConnection(ShippingPeer::DATABASE_NAME);
		}

		if ($values instanceof Criteria) {
			$criteria = clone $values; 		} elseif ($values instanceof Shipping) {

			$criteria = $values->buildPkeyCriteria();
		} else {
						$criteria = new Criteria(self::DATABASE_NAME);
			$criteria->add(ShippingPeer::ID, (array) $values, Criteria::IN);
		}

				$criteria->setDbName(self::DATABASE_NAME);

		$affectedRows = 0; 
		try {
									$con->begin();
			$affectedRows += ShippingPeer::doOnDeleteCascade($criteria, $con);
			$affectedRows += BasePeer::doDelete($criteria, $con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected static function doOnDeleteCascade(Criteria $criteria, Connection $con)
	{
				$affectedRows = 0;

				$objects = ShippingPeer::doSelect($criteria, $con);
		foreach($objects as $obj) {


			include_once 'lib/model/ShippingI18n.php';

						$c = new Criteria();
			
			$c->add(ShippingI18nPeer::ID, $obj->getId());
			$affectedRows += ShippingI18nPeer::doDelete($c, $con);
		}
		return $affectedRows;
	}

	
	public static function doValidate(Shipping $obj, $cols = null)
	{
		$columns = array();

		if ($cols) {
			$dbMap = Propel::getDatabaseMap(ShippingPeer::DATABASE_NAME);
			$tableMap = $dbMap->getTable(ShippingPeer::TABLE_NAME);

			if (! is_array($cols)) {
				$cols = array($cols);
			}

			foreach($cols as $colName) {
				if ($tableMap->containsColumn($colName)) {
					$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
					$columns[$colName] = $obj->$get();
				}
			}
		} else {

		}

		$res =  BasePeer::doValidate(ShippingPeer::DATABASE_NAME, ShippingPeer::TABLE_NAME, $columns);
    if ($res !== true) {
        $request = sfContext::getInstance()->getRequest();
        foreach ($res as $failed) {
            $col = ShippingPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
            $request->setError($col, $failed->getMessage());
        }
    }

    return $res;
	}

	
	public static function retrieveByPK($pk, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$criteria = new Criteria(ShippingPeer::DATABASE_NAME);

		$criteria->add(ShippingPeer::ID, $pk);


		$v = ShippingPeer::doSelect($criteria, $con);

		return !empty($v) > 0 ? $v[0] : null;
	}

	
	public static function retrieveByPKs($pks, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$objs = null;
		if (empty($pks)) {
			$objs = array();
		} else {
			$criteria = new Criteria();
			$criteria->add(ShippingPeer::ID, $pks, Criteria::IN);
			$objs = ShippingPeer::doSelect($criteria, $con);
		}
		return $objs;
	}

} 
if (Propel::isInit()) {
			try {
		BaseShippingPeer::getMapBuilder();
	} catch (Exception $e) {
		Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
	}
} else {
			require_once 'lib/model/map/ShippingMapBuilder.php';
	Propel::registerMapBuilder('lib.model.map.ShippingMapBuilder');
}
